package com.cms.fom.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.cms.common.exception.RRException;
import com.cms.fom.entity.vo.MonitorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cms.fom.entity.MonitorEntity;
import com.cms.fom.service.MonitorService;
import com.cms.common.utils.PageUtils;
import com.cms.common.utils.R;



/**
 * 
 *
 * @author weixiaochun
 * @email xiaochun0121@163.com
 * @date 2022-03-17 00:58:15
 */
@RestController
@RequestMapping("fom/monitor")
public class MonitorController {
    @Autowired
    private MonitorService monitorService;

    /**
     * 上传健康码
     */
    @RequestMapping("/uploadImg")
    //@RequiresPermissions("fom:monitor:save")
    public R uploadImg(@RequestParam Long id, @RequestParam String url){
       try {
           Boolean flag = monitorService.uploadImg(id, url);
           return R.ok();
       }catch (RRException e){
           System.out.println(e.getMsg());
           return R.error(e.getMsg());
       }
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("fom:monitor:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = monitorService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("fom:monitor:info")
    public R info(@PathVariable("id") Long id){
		MonitorEntity monitor = monitorService.getById(id);

        return R.ok().put("monitor", monitor);
    }

    /**
     * 获取详细信息
     */
    @RequestMapping("/detailInfo/{id}")
    //@RequiresPermissions("fom:monitor:info")
    public R detailInfo(@PathVariable("id") Long id){
        MonitorVo monitorVo = monitorService.detailInfo(id);

        return R.ok().put("monitorVo", monitorVo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("fom:monitor:save")
    public R save(@RequestBody MonitorEntity monitor){
		monitorService.save(monitor);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("fom:monitor:update")
    public R update(@RequestBody MonitorEntity monitor){
		monitorService.updateById(monitor);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("fom:monitor:delete")
    public R delete(@RequestBody Long[] ids){
		monitorService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
